package com.stn.zjx.givingtreasure.net.impl;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.stn.zjx.givingtreasure.net.UserAddressApi;
import com.stn.zjx.givingtreasure.net.UserDynamicApi;
import com.stn.zjx.givingtreasure.net.UserRealAuthApi;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class UserDynamicNetImpl {


    /**
     * @apiNote 上传动态
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void ad_dynamic(String token,
                                  String dynamicContent,
                                      String dynamicProvince,
                                      String dynamicCity,
                                      String dynamicArea,
                                      String dynamicAddress,
                                       String dynamicImgs,
                                      String dynamicVideoPath,
                                      Long dynamicVideoSize,
                                      Long dynamicVideoTime,
                                      Integer dynamicVideoWidth,
                                      Integer dynamicVideoHeight,
                                      double locationLongitude,
                                      double locationLatitude,
                                      String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("dynamicContent",dynamicContent);
            jsonObject.put("dynamicProvince",dynamicProvince);
            jsonObject.put("dynamicCity",dynamicCity);
            jsonObject.put("dynamicArea",dynamicArea);
            jsonObject.put("dynamicAddress",dynamicAddress);
            jsonObject.put("dynamicImgs",dynamicImgs);
            jsonObject.put("locationLongitude",locationLongitude);
            jsonObject.put("locationLatitude",locationLatitude);


            if(!TextUtils.isEmpty(dynamicVideoPath)){
                jsonObject.put("dynamicVideoPath",dynamicVideoPath);
                jsonObject.put("dynamicContentType",1);
                jsonObject.put("dynamicVideoSize",dynamicVideoSize);
                jsonObject.put("dynamicVideoTime",dynamicVideoTime);
                jsonObject.put("dynamicVideoWidth",dynamicVideoWidth);
                jsonObject.put("dynamicVideoHeight",dynamicVideoHeight);

            }
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserDynamicApi.add_dynamic)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }


    /**
     * @apiNote 通过定位查询动态
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_dynamic_location(String token,
                                  Integer pageNow,
                                  Integer pageSize,
                                  String dynamicCity,
                                  String dynamicArea,
                                  double locationLongitude,
                                  double locationLatitude,
                                  String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("pageNow",pageNow);
            jsonObject.put("pageSize",pageSize);
            jsonObject.put("dynamicCity",dynamicCity);
            jsonObject.put("dynamicArea",dynamicArea);
            jsonObject.put("locationLongitude",locationLongitude);
            jsonObject.put("locationLatitude",locationLatitude);

            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserDynamicApi.query_dynamic_location)
                .tag(tag)
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);

    }

    /**
     * @apiNote 通过动态ID查询出动态详情
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_dynamic_detail(String token,
                                              Integer userDynamicId,
                                              String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userDynamicId",userDynamicId);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserDynamicApi.query_dynamic_detail)
                .tag(tag)
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);

    }
    /**
     * @apiNote 推荐附近
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_dynamic_recommend(String token,
                                              Integer pageNow,
                                              Integer pageSize,
                                              String dynamicCity,
                                              String dynamicArea,
                                              double locationLongitude,
                                              double locationLatitude,
                                              String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("pageNow",pageNow);
            jsonObject.put("pageSize",pageSize);
            jsonObject.put("dynamicCity",dynamicCity);
            jsonObject.put("dynamicArea",dynamicArea);
            jsonObject.put("locationLongitude",locationLongitude);
            jsonObject.put("locationLatitude",locationLatitude);

            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserDynamicApi.query_dynamic_recommend)
                .tag(tag)
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);

    }
}
